from django.shortcuts import render
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.core.context_processors import csrf
from django.db import connection
from django.contrib.sessions.models import Session
from models import Reservation

def resrv(request, room_id):

    checkin = request.session['checkin']
    checkout = request.session['checkout']
    userid = request.session['userid']

    cursor = connection.cursor()

    sql = "INSERT INTO reservation_reservation (room_id, guest_id, check_in, check_out) VALUES(%d,%d,'%s','%s')" % (int(room_id), int(userid), checkin, checkout)

    cursor.execute(sql)

    data = {'checkin': request.session['checkin'], 'checkout': request.session['checkout'], 'userid': request.session['userid'], 'user': request.user}
    return render_to_response("reserv.html",data)